//
//  BroadcastViewController.m
//  wAudioShare
//
//  Created by 赵帅 on 14-2-11.
//  Copyright (c) 2014年 赵帅. All rights reserved.
//

#import "RadioViewController.h"
#import "MMProgressHUD.h"

@interface RadioViewController ()
<servicePlayListDemoDelegate>
{
    NSDictionary * radioChannelDic;
}

@end

@implementation RadioViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSString * path = [[NSBundle mainBundle] bundlePath];
    path = [path stringByAppendingPathComponent:@"RadioList.plist"];
    radioChannelDic = [NSDictionary dictionaryWithContentsOfFile:path];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navigation methods
-(NSString *)navigationBarTitle
{
    return NSLocalizedString(@"RADIO_MUSIC",@"");
}

-(BOOL)isNewVersionButtonEnabled
{
    return YES;
}

#pragma mark -
#pragma mark UITableView Delegate & Datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[radioChannelDic allKeys] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    else
    {
        for(UIView * subview in [cell.contentView subviews])
        {
            [subview removeFromSuperview];
        }
    }
    
    // Configure the cell
    cell.textLabel.text = [radioChannelDic allKeys][indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
    
    [[GlobalService sharedInstance] playListDemo:self musicURL:[radioChannelDic allValues][indexPath.row] masterIP:nil groupName:nil];
}

-(void)servicePlayListDemoCallBack:(NSDictionary*)dicCallBack
{    
    if([[dicCallBack objectForKey:@"responsestatus"] intValue] == [SERVICE_SUCCESS intValue])
    {
        [MMProgressHUD dismiss];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"JumptoControlView" object:nil];
    }
    else
    {
        [MMProgressHUD dismissWithError:NSLocalizedString(@"MUSIC_PLAY_FAILED",@"")];
    }
}

-(void)serviceSetPlayModeCallBack:(NSDictionary*)dicCallBack{}

@end
